<?php
	session_start();
	$valid=0;
	$post=0;
	if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1800)) 
	{
		// last request was more than 30 minates ago
		session_destroy();   // destroy session data in storage
		session_unset();     // unset $_SESSION variable for the runtime
	}
	$_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp
	if(isset($_SESSION['username']))
		{
			$username = $_SESSION['username'];
			$password = $_SESSION['password'];
			$valid=1;
		}
	else if(isset($_POST['userid']))
	{

		$username = $_POST['userid'];
		$password = $_POST['password'];
		$post=1;
	}
	else
	{
		$valid = 0;
		$post=0;
	}
	$username = $_POST['userid'];
	$password = $_POST['password'];
	
	include("include/connect.php");
	$check = mysqli_query($con, "SELECT * FROM customer where emailid ='".$username."' and password = '".$password."'")OR DIE(mysqli_errno());
	$numrows = mysqli_num_rows($check); 
	if($numrows >0 ){
		if($valid == 0  && $post == 1){
			$chk  = mysqli_fetch_assoc($check);
			$firstName = $chk['firstName'];
			$valid=1;
			$_SESSION['username']=$username;
			$_SESSION['password']=$password;
			$_SESSION['uName']=$chk['firstName'];
			$_SESSION['CID']= $chk['CustomerID'];
			echo "success";
		}else{
			echo "already logged in";
		}
	}else{
		echo "failure";
	}
	if(isset($_GET['action']) == "model"){
		session_start();
		$id = $_POST['id'];
		$_SESSION['model_id'] = $id;
	}
	
	
?>